<?php

namespace App\Services\Elasticsearch;
use Elasticsearch\ClientBuilder;

class EsMessage
{
    private static $client;
    private static $esmessage;

    private function __construct (){
        self::$client = ClientBuilder::create()->setHosts(['127.0.0.1:9200'])->build();
    }

    private function __clone (){
        // 禁止类外克隆
    }

    public static function connent (){
        if (!self::$esmessage instanceof self){
            self::$esmessage = new self();
        }
        return self::$esmessage;
    }

    public function esInit (){
        $params = [
            'index' => 'Shop',
            'body' => [
                'settings' => [
                    'number_of_shards' => 3,
                    'number_of_replicas' => 2
                ],
                'mappings' => [
                    'users' => [
                        '_source' => [
                            'enabled' => true
                        ],
                        'properties' => [
                            'uid' => [
                                'type' => 'integer',
                                'analyzer' => 'standard'
                            ],
                            'name' => [
                                'type' => 'text',
                                'analyzer' => 'ik_max_word'
                            ],
                            'icon' => [
                                'type' => 'string'
                            ],
                            'tel' => [
                                'type' => 'integer',
                                'analyzer' => 'standard'
                            ],
                            'sexs' => [
                                'type' => 'integer',
                                'analyzer' => 'standard'
                            ],
                            'vip' => [
                                'type' => 'integer',
                                'analyzer' => 'standard'
                            ],
                            'grade' => [
                                'type' => 'integer',
                                'analyzer' => 'standard'
                            ],
                            'group' => [
                                'type' => 'integer',
                                'analyzer' => 'standard'
                            ],
                            'tag' => [
                                'type' => 'text',
                                'analyzer' => 'standard'
                            ],
                        ]
                    ]
                ]
            ]
        ];
    }
}
